package lc.q51_100;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

public class Q78 {

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> result = new ArrayList<>();
        Deque<Integer> deque = new ArrayDeque<>();
        dfs(nums, 0, deque, result);
        return result;
    }

    private void dfs(int[] nums, int start, Deque<Integer> deque, List<List<Integer>> result) {
        result.add(new ArrayList<>(deque));
        if (start == nums.length) {
            return;
        }
        for (int i = start; i < nums.length; i++) {
            deque.addLast(nums[i]);
            dfs(nums, i + 1, deque, result);
            deque.removeLast();
        }
    }

    public static void main(String[] args) {
        List<List<Integer>> subsets = new Q78().subsets(new int[]{1, 2, 4});
        System.out.println(subsets);
    }

}
